<#include '/admin/header.html' > <#assign
dateFormat="com.enation.framework.directive.DateformateDirective"?new()>
<style>
.input_text{
	width: 95%;
}
</style>
<div id="loading"></div>
<div class="main">
	<form id="orderform">
		<div class='buttonArea' style="height: auto">
			<!-- <a href="javascript:void(0)" class="easyui-linkbutton"
				data-options="plain:true" onclick="append()">添加</a> -->
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true" onclick="del()">删除</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true" onclick="newTab('回收站','${ctx}/shop/admin/order/trash-list.do')">回收站</a>
			 <span style="float: right;"> 
			 	<span id="simpleSearch"> 
				 	<input id="searchKeyword" class="input_text" type="text" maxlength="50" value="" size="30" style="width: 300px;" placeholder="请输入订单号,收货人" name="searchKeyWord">
					<a href="javascript:void(0)" class="easyui-linkbutton" id="search" data-options="plain:true" onclick="searchOrder()">搜索</a>
				</span> 
				<a href="javascript:void(0)" class="button" data-options="plain:true" id="aAdvanced">高级搜索</a> 
			</span>
		</div>

		<div style="display: block;" class="searchAdvanced">
			<input id="Advanced" name="Advanced" type="hidden" value="0" />
			<table width="98%" border="0" cellspacing="0" cellpadding="8">
				<tr>
					<td width="70" align="right">订单号</td>
					<td><input type="text" value="" id="sn" class="input_text">
					</td>

					<td width="70" align="right">下单时间</td>
					<td><input class="easyui-datebox" style="width: 90px;height: 28px;"
						id="start_time" data-options="buttons:buttons" /> <span>&nbsp;&nbsp;~&nbsp;&nbsp;</span>
						<input class="easyui-datebox" style="width: 90px;height: 28px;" id="end_time"
						data-options="buttons:e_buttons" /></td>

					<td width="70" align="right">订单状态</td>
					<td>
						<select id="status" class="inputSelect valid">
							<option value="">---所有---</option> 
							<#list statusList as status>
								<option value="${status.key}">${status.value}</option> 
							</#list>
						</select>
					</td>

					<td width="70" align="right">收货人</td>
					<td><input type="text" value="${name!''}" id="ship_name"
						class="input_text"></td>
				</tr>
				<tr>
					<td width="70" align="right">付款状态</td>
					<td>
						<select id="paystatus" class="inputSelect valid" style="width: 145px;">
							<option value="">---所有---</option> 
							<#list payStatusList as status>
								<option value="${status.key}">${status.value}</option> 
							</#list>
						</select>
					</td>
					<td width="70" align="right">发货状态</td>
					<td width="272">
						<select id="shipstatus" class="inputSelect valid" style="width: 200px;">
							<option value="">---所有---</option>
							<#list shipList as status>
								<option value="${status.key}">${status.value}</option> 
							</#list>
						</select>
					</td>
					
					<td width="70" align="right">配送方式</td>
					<td><select id="shipping_type" class="inputSelect valid"
						style="width: 145px;">
							<option value="">---所有---</option> <#list shipTypeList as slist>
							<option value="${slist.type_id}">${slist.name}</option> </#list>
					</select></td>
					<td width="70" align="right">支付方式</td>
					<td><select id="payment_id" class="inputSelect valid"
						style="width: 145px;">
							<option value="">---所有---</option> <#list payTypeList as plist>
							<option value="${plist.id}">${plist.name}</option> </#list>
					</select></td>
				</tr>
				<tr>
					<td width="70" align="right"></td>
					<td colspan="7" align="center"><a id="searchAdvance"
						class="button blueButton" onclick="searchOrder()"
						href="javascript:;">开始搜索</a></td>
				</tr>
			</table>
		</div>

		<div class="clear height10"></div>

		<div class="shadowBoxWhite tableDiv">
			<table class="easyui-datagrid"
				data-options="url:'${ctx}/shop/admin/order/list-json.do?order_state=wait_pay',pageList: [5,10,15,20],pageSize:${pageSize},fitColumns:'true'"
				pagination="true" width="width" id="orderdata" sortName="order_id" sortOrder="asc">
				<thead>
					<tr>
					
						<th data-options="field:'order_id',checkbox:true,width:100"></th>
						<th data-options="field:'sn',width:150" formatter="forsn">订单号</th>
						<th data-options="field:'create_time',width:100,sortable:true" formatter="formatDate">下单日期</th>
						<th data-options="field:'sale_cmpl_time',width:100,sortable:true" formatter="formatDate">发货日期</th>		
						<th data-options="field:'need_pay_money',width:100,sortable:true" formatter="forMoney">订单总额</th>
						<th data-options="field:'paymoney',width:100,sortable:true" formatter="forMoney">实付金额</th>
						<th data-options="field:'ship_name',width:100">收货人</th>
						<th data-options="field:'status',width:100,sortable:true" formatter="forStruts">订单状态</th>
						<th data-options="field:'pay_status',width:100,sortable:true" formatter="forpay">付款状态</th>
						<th data-options="field:'ship_status',width:100,sortable:true" formatter="forship">发货状态</th>
						<th data-options="field:'shipping_type',width:100,sortable:true">配送方式</th>
						<th data-options="field:'payment_name',width:100,sortable:true">支付方式</th>
						<th data-options="field:'action',width:100" formatter="formatAction">操作</th>
						
						
					</tr>
				</thead>
			</table>
		</div>
	</form>
</div>
<script type="text/javascript">
	function forsn(value,row,index){
		var val="<a href='#' onclick=\"newTab('查看订单详细','${ctx}/shop/admin/order/detail.do?orderId="+row.order_id+"')\">"+row.sn+"</a>"
		return val;
	}
	function forMoney(value, row, index) {
		var val = "￥" + value;
		return val;
	}
	function formatDate(value,row,index){
		if(value==null||value==0){
			return "";
		}
		else{
			return getFormatDateByLong(value, "yyyy-MM-dd");
		}
		
	}
	
	//订单状态
	function forStruts(value, row, index) {
		if(row.is_cancel==1){
			return "申请取消订单";
		}
		var val;
		val = getType(${status_Json},value);
		return val;
	}
	
	//付款状态
	function forpay(value,row,index){
		var val;
		val = getType(${payStatus_Json},value);
		return val;
	}
	
	//发货状态
	function forship(value,row,index){
		var val;
		val = getType(${ship_Json},value);
		return val;
	}
	
	
	function getType(exMap,value){
		var val;
		$.each(exMap,function(key,values){ 
		    if(value==values.key){
		    	val=values.value;
		    }
		});
		return val;
	}
	
	function del() {
		var rows = $('#orderdata').datagrid("getSelections");
		if (rows.length < 1) {
			$.Loading.error("请选择要放入回收站的订单");
			return;
		}
		if (!confirm("确认要将这些订单放入回收站？")) {
			return;
		}
		var options = {
			url : "${ctx}/shop/admin/order/delete.do?ajax=yes",
			type : "POST",
			dataType : 'json',
			success : function(result) {
				if (result.result == 1) {
					$('#orderdata').datagrid("reload");
				}
				if (result.result == 0) {
					$.Loading.success(result.message);
				}
			},
			error : function(e) {
				$.Loading.error("出现错误 ，请重试");
			}
		};

		$('#orderform').ajaxSubmit(options);	
}
	
	var buttons = $.extend([], $.fn.datebox.defaults.buttons);
	buttons.splice(1, 0, {
	text: '清空',
	handler: function(target){
		 $('#start_time').datebox('setValue',"");
	}
	});
	
	var e_buttons = $.extend([], $.fn.datebox.defaults.buttons);
	e_buttons.splice(1, 0, {
	text: '清空',
	handler: function(target){
		 $('#end_time').datebox('setValue',"");
	}
	});
    
    
function formatAction(value,row,index){
	var val="<a class='edit' title='查看' href='#' onclick=\"newTab('查看订单详细','${ctx}/shop/admin/order/detail.do?orderId="+row.order_id+"&sn="+row.sn+"&logi_no="+row.logi_no+"&uname="+row.uname+"&ship="+row.ship_name+"&status="+row.status+"')\"></a>";
	return val;
		
	}
	
	$(function(){
		$(".searchAdvanced").hide();
		//高级查询按钮
	    $("#aAdvanced").click(function () {
	        if ($("#Advanced").val() == "0") {
	            $("#Advanced").val(1);
	            $("#simpleSearch").hide();
	            //$("#aAdvanced").text("简单搜索")
	            $("#aAdvanced").addClass("searchAdvancedS");
	        } else {
	            $("#Advanced").val(0);
	            $("#simpleSearch").show();
	            //$("#aAdvanced").text("高级搜索");
	            $("#aAdvanced").removeClass("searchAdvancedS");
	        }
	        $(".searchAdvanced").slideToggle("slow");
	    });
	})
	
	function searchOrder(){
	var searchtype = $("#Advanced").val();
	var keyword = $("#searchKeyword").val();
	
	
	var start_time = $('#start_time').datebox('getValue');
	var end_time = $('#end_time').datebox('getValue');  
	
	if(start_time != '' && end_time != ''){
		if(end_time < start_time){
			$.Loading.error("结束时间不能小于开始时间");
			return ;
		}
	}
	var status = $("#status").val();
	var sn = $("#sn").val();
	var ship_name = $("#ship_name").val();
	var paystatus =	$("#paystatus").val();
	var	shipstatus = $("#shipstatus").val();
	var	shipping_type = $("#shipping_type").val();
	var	payment_id = $("#payment_id").val();
	
	
	$("#orderdata").datagrid('load', {
		 stype:searchtype,
		 keyword:keyword,
		 
		 start_time:start_time,
		 end_time:end_time,
		 status:status,
		 sn:sn,
		 ship_name:ship_name,
		 paystatus:paystatus,
		 shipstatus:shipstatus,
		 shipping_type:shipping_type,
		 payment_id:payment_id,
		 page:1
    });
}

	function formatTime(value,row,index){
		var val = getFormatDateByLong(value, "yyyy-MM-dd");
		return val;
	}
	
</script>

<#include '/admin/footer.html' >


